{
  "properties" : { },
  "id" : "73c9966f32a24180a0e9612bb2b66940",
  "script" : null,
  "groupId" : "c77728f004b145939161e526695eb38c",
  "name" : "支付回调",
  "createTime" : null,
  "updateTime" : 1733843585066,
  "lock" : null,
  "createBy" : null,
  "updateBy" : null,
  "path" : "/callback",
  "method" : "GET",
  "parameters" : [ {
    "name" : "pid",
    "value" : null,
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "name",
    "value" : null,
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "money",
    "value" : null,
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "out_trade_no\t",
    "value" : null,
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "trade_no",
    "value" : "202412102112387238",
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "param",
    "value" : null,
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "trade_status",
    "value" : "TRADE_SUCCESS",
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "type",
    "value" : null,
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "sign",
    "value" : null,
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "sign_type",
    "value" : null,
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ],
  "options" : [ {
    "name" : "require_login",
    "value" : "false",
    "description" : "该接口需要登录才允许访问",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ],
  "requestBody" : "",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 500,\n    \"message\": \"系统内部出现错误\",\n    \"data\": null,\n    \"timestamp\": 1733836493428,\n    \"executeTime\": 78\n}",
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : null
}
================================
import response;
import log
import http

if (trade_status = "TRADE_SUCCESS") { //标记支付成功 
    //查找当前的状态
    var order_re = db.table("orders").where().eq("order_no", trade_no).selectOne()
    if (order_re != null) {
        if (order_re.status == "TRADE_SUCCESS") { //已经处理过了
            log.info("order_re-->" + order_re)
        } else {
            db_res = db.table("orders").primary("id").update({
                id: order_re.id,
                status: trade_status, //更新状态
                transaction_id: trade_no,
                pay_time: now()
            })
            log.info("db_res-->" + db_res)

            //智能体交互部分
            const requestUrl = "https://api.coze.cn/v3/chat"
            let appkey = "pat_xqSq4XAsAA5QzmBl5JL4teiyOVvCipC2HDWyXXkFMKoKmd6CZ3MaTkI1HV0CMSRM"
            let param = {
                "bot_id": "7445192650988781609",
                "user_id": "123123",
                "stream": false,
                "auto_save_history": true,
                "additional_messages": [{
                    "role": "user",
                    "content": order_re.content,
                    "content_type": "text"
                }]
            }
            var result = http.connect(requestUrl).contentType('application/json').header("Authorization", "Bearer " + appkey).body(param).post().getBody()
            log.info("result" + result)
            // 更新记录
            db_res = db.table("orders").primary("id").update({
                id: order_re.id,
                ai_status: result.data.status, //更新状态
                conversation_id: result.data.conversation_id,
                chat_id: result.data.id,
            })
            log.info("db_res-->" + db_res)
            //执行定时任务
            
            return response.text('success');
        }
    } else {
        exit 400, '订单不存在';
        return response.text('fail');
    }
}

return response.text('fail');